package cn.wlbw.dao;

import cn.hutool.db.DbUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import cn.wlbw.model.Navs;
import org.nutz.conf.NutConf;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;
import org.osgl.util.N;

import java.util.List;

public class NDao {
    public static Dao dao = new NutDao(DbUtil.getDs());
    private Log logger = LogFactory.get();

    public NDao() {
        NutConf.USE_FASTCLASS = false;
    }

    public static NDao getInstance() {
        return NDao.SingletonHolder.instance;
    }

    public static void main(String[] args) {
//        dao.create(Navs.class, true);
        NDao nDao = new NDao();
        List<Navs> navs = nDao.getNavs(null);
        System.out.println();
    }

    public List<Navs> getNavs(String id) {
        List<Navs> navs = dao.query(Navs.class, Cnd.where("pid", "=", id));
        for (Navs nav : navs) {
            if (nav.isSpread()){
                nav.setChildren(getNavs(nav.getId()));
            }
        }
        return navs;
    }

    private static class SingletonHolder {
        private static NDao instance = new NDao();

        private SingletonHolder() {
        }
    }
}
